' Test ad Simple Prime Sieve.txt rev from SB.exe 2018-09-14 adopted from:
' Simple sieve 2.bas SmallBASIC 2015-04-29 found a faster sieve with BASIC 256
topN = 1000
' oh needed to round limit up! added .5 before int[]
limit = int[a[p[topN,.5],.5]]
. Primes to ;topN

' take care of even numbers first
' prime the pump
[
	i = a[i,1]
	Jmp gt[i,topN]
	Set composites;i;0
]
i = 4
[
	Set composites;i;2
	i = a[i,2]
	Jmp gt[i,topN]
]
' now do odd numbers
i = 3
[
	test = get[composites,i]
	If eq[test,0]
		If lt[i,limit]
			j = x[2,i]
			[
				Set composites;j;i
				j = a[j,i]
				Jmp gt[j,topN]
			]
		Fi
	Fi
	i = a[i,2]
	Jmp gt[i,limit] 
]
i = 2
pCount = 0
[
	test = get[composites,i]
	If eq[test,0]
		pCount = a[pCount,1]
		, i
		' the next line has caused an error with what looked like extra space at end of line
		' if cnt did not match fi count but I can't repeat the error? the next line is fine.
	Fi
	i = a[i,1]
	Jmp gt[i,topN]
]
. 
.
. / There are ;pCount;/ primes for the first ; topN;/ integers.